<?php



class Request {
    /**
     * @var Request
     */
    static protected $instance;
    protected $params;
    
    /**
     * 私有初始化， 禁止外部使用new创建对象
     */
    protected function __construct() {}

    /**
     * 单例模式
     *
     * @return Request
     */
    static public function &getInstance() {
        if (!isset(self::$instance)) {
            self::$instance = new Request();
        }
        return self::$instance;
    }
    
    /**
     * 设置访问参数
     *
     * @param array $params
     */
    public function setParams($params, $key = null) {
        if (empty($key)) {
            $this->params = $params;
        } else {
            $this->params[$key] = $params;
        }
    }
    
    /**
     * 获取访问参数
     *
     * @param string $key
     * @return mixed
     */
    public function getParams($key = null) {
        if (empty($key)) {
            return $this->params;
        }
        
        return $this->params[$key];
    }
    
    public function render404() {
        $status = "HTTP/1.1 404 Not Found";
        header($status);
        echo '404 Not Found';
        exit();
    }
}
